package gov.nist.ssd.swqb.test.util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ToListConverter {

	private int size;
	
	private ToListConverter(int i) {
		this.size = i;
	}
	
  public static <X> List<X> asList(Iterable<X> i) {
    return asList(i.iterator());
  }
  
  public static <X> List<X> asList(Iterator<X> i) {
    List<X> res = new ArrayList<X>();
    
    while(i.hasNext())
      res.add(i.next());
    
    return res;
  }
	
  public static ToListConverter makeListWithFirst(int count) {
  	return new ToListConverter(count);
  }
  
  public <X> List<X> elementsFrom(Iterable<X> it) {
  	return asListFrom(it.iterator());
  }
  
  public <X> List<X> asListFrom(Iterator<X> it) {
  	List<X> res = new ArrayList<X>();
  	
  	int i = 0;
  	while(it.hasNext() && i<size) {
  		res.add(it.next());
  		i++;
  	}
  	
  	return res;
  }
}
